/**
 * @Title: CityService
 * @Package cn.com.yiqi.wsc
 * @Description: TODO
 * Copyright: Copyright (c) 2016
 * Company: 成都壹柒互动科技有限公司
 * @author 会员系统组-林威
 * @date 2017/2/17 16:00
 * @version V1.0
 */
package cn.com.yiqi.wsc;

import cn.com.yiqi.wsc.dao.CityMapper;
import cn.com.yiqi.wsc.entity.City;
import cn.com.yiqi.wsc.entity.CityExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 *@ClassName: CityService
 * Description: TODO
 * @author 会员系统组-林威
 * @date 2017/2/17 16:00
 *
 */
@Service
public class CityService {

    @Autowired
    CityMapper cityDao;

    /**
     * 获取省code
     * */
    public String findProvicnCode(String pro){
        CityExample example = new CityExample();
        String likeValue = pro+"%";
        example.createCriteria().andCityNameLike(likeValue);
        List<City> citys = cityDao.selectByExample(example);
        if(citys != null && citys.size() > 0){
            return citys.get(0).getCityCode();
        }
        return  null;
    }

    /**
     * 获取城市code
     * */
    public String findCityByProviceAndCityName(String proCode, String city) {
        CityExample example = new CityExample();
        String likeValue = city+"%";
        example.createCriteria().andSuperiorCityCodeEqualTo(proCode).andCityNameLike(likeValue);
        List<City> citys = cityDao.selectByExample(example);
        if(citys != null && citys.size() > 0){
            return citys.get(0).getCityCode();
        }
        return  null;
    }

    /**
     * 获取下级城市
     * */
    public List<City> findBySub(String subCode) {
        CityExample ex = new CityExample();
        if(null == subCode){
            ex.createCriteria().andCityLevelEqualTo(1);
        }else {
            ex.createCriteria().andSuperiorCityCodeEqualTo(subCode);
        }
        return cityDao.selectByExample(ex);
    }
}
